
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>fastlmm Documentation &#8212; fastlmm 0.0.1 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="_static/classic.css" />
    
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/doctools.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="nav-item nav-item-0"><a href="#">fastlmm 0.0.1 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">fastlmm</span></code> Documentation</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="fastlmm-documentation">
<h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">fastlmm</span></code> Documentation<a class="headerlink" href="#fastlmm-documentation" title="Permalink to this headline">¶</a></h1>
<p>FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed Models, is a program for performing both
single-SNP and SNP-set genome-wide association studies (GWAS) on extremely large data sets.</p>
<p>See <a class="reference external" href="https://github.com/fastlmm/FaST-LMM/blob/master/README.md">FaST-LMM’s README.md</a> for installation instructions, documentation, code, and a bibliography.</p>
<dl class="field-list simple">
<dt class="field-odd">new</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<p><a class="reference internal" href="#fastlmm.association.single_snp" title="fastlmm.association.single_snp"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp()</span></code></a> now supports multiple phenotypes and related features (<a class="reference external" href="https://nbviewer.jupyter.org/github/fastlmm/FaST-LMM/blob/master/doc/ipynb/fastlmm2021.ipynb">notebook demonstrating new features</a>).</p>
<dl class="field-list simple">
<dt class="field-odd">Code</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<ul class="simple">
<li><p><a class="reference external" href="https://pypi.org/project/fastlmm/">PyPi</a></p></li>
<li><p><a class="reference external" href="https://github.com/fastlmm/FaST-LMM">GitHub</a></p></li>
</ul>
<dl class="field-list simple">
<dt class="field-odd">Contacts</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<ul class="simple">
<li><p>Email the developers at <a class="reference external" href="mailto:fastlmm-dev&#37;&#52;&#48;python&#46;org">fastlmm-dev<span>&#64;</span>python<span>&#46;</span>org</a>.</p></li>
<li><p><a class="reference external" href="mailto:fastlmm-user-join&#37;&#52;&#48;python&#46;org?subject=Subscribe">Join</a> the user discussion and announcements
list (or use <a class="reference external" href="https://mail.python.org/mailman3/lists/fastlmm-user.python.org">web sign up</a>).</p></li>
<li><p><a class="reference external" href="https://github.com/fastlmm/PySnpTools/issues">Open an issue</a> on GitHub.</p></li>
<li><p><a class="reference external" href="https://fastlmm.github.io/">Project Home</a> (including bibliography).</p></li>
</ul>
<div class="section" id="single-snp">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp</span></code><a class="headerlink" href="#single-snp" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.single_snp">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">single_snp</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mixing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar_by_chrom</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">leave_out_one_chrom</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">h2</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_delta</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">GB_goal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interact_with_snp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_full_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_low_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">map_reduce_outer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pvalue_threshold</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">random_threshold</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">random_seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.single_snp" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing single SNP GWAS using cross validation over the chromosomes and REML. Will reorder and intersect IIDs as needed.
(For backwards compatibility, you may use ‘leave_out_one_chrom=False’ to skip cross validation, but that is not recommended.)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> – SNPs to test. Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.
If you give a string, it should be the base name of a set of PLINK Bed-formatted files.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>pheno</strong> – <p>A one or more phenotypes: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example,
<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
Any individual with missing all values will be removed.
If more than one phenotype is given, then K1 (the 2nd kernel) cannot be given.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p>
</p></li>
<li><p><strong>K0</strong> – <p>similarity matrix or SNPs from which to create a similarity matrix. If not given, will use test_snps.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.
If you give a string, it should be the base name of a set of PLINK Bed-formatted files.
If leave_out_one_chrom is True, can be a dictionary from chromosome number to any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>
or the name a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a>-formated file.
If leave_out_one_chrom is False, can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a> or
name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a>-formated file.</p>
</p></li>
<li><p><strong>K1</strong> – second similarity matrix or SNPs from which to create a second similarity matrix, optional. (Also, see ‘mixing’).</p></li>
<li><p><strong>mixing</strong> (<em>number</em>) – Weight between 0.0 (inclusive, default) and 1.0 (inclusive) given to K1 relative to K0.
If you give no mixing number and a K1 is given, the best weight will be learned.</p></li>
<li><p><strong>covar</strong> – <p>covariate information, optional: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
Missing values are not supported.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p>
</p></li>
<li><p><strong>covar_by_chrom</strong> – <p>dictionary from chromosome number to covariate information, optional:
The covariate information
can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.
If given, leave_out_one_chrom must be True.
Both covar and covar_by_chrom can be given.
Missing values are not supported.</p>
</p></li>
<li><p><strong>leave_out_one_chrom</strong> (<em>boolean</em>) – Perform single SNP GWAS via cross validation over the chromosomes. Default to True.
(Warning: setting False can cause proximal contamination.)</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created. The output format is tab-delimited text.</p></li>
<li><p><strong>h2</strong> (<em>number</em>) – A parameter to LMM learning, optional
If not given will search for best value.
If mixing is unspecified, then h2 must also be unspecified.</p></li>
<li><p><strong>log_delta</strong> (<em>number</em>) – a re-parameterization of h2 provided for backwards compatibility. h2 is 1./(exp(log_delta)+1)</p></li>
<li><p><strong>cache_file</strong> (<em>file name</em>) – Name of  file to read or write cached precomputation values to, optional.
If not given, no cache file will be used.
If given and file does not exist, will write precomputation values to file.
If given and file does exist, will read precomputation values from file.
The file contains the S and U from the decomposition of the training matrix and other values.
It is in Python’s np.savez (*.npz) format.
Calls using the same cache file should have the same inputs (pheno, K0, K1, covar) but test_snps can differ.</p></li>
<li><p><strong>GB_goal</strong> (<em>number</em>) – gigabytes of memory the run should use, optional. If not given, will read the test_snps in blocks the same size as the kernel,
which is memory efficient with little overhead on computation time.</p></li>
<li><p><strong>interact_with_snp</strong> – index of a covariate to perform an interaction test with.
Allows for interaction testing (interact_with_snp x snp will be tested)
default: None</p></li>
<li><p><strong>force_full_rank</strong> (<em>Boolean</em>) – Even if kernels are defined with fewer SNPs than IIDs, create an explicit iid_count x iid_count kernel. Cannot be True if force_low_rank is True.</p></li>
<li><p><strong>force_low_rank</strong> (<em>Boolean</em>) – Even if kernels are defined with fewer IIDs than SNPs, create a low-rank iid_count x sid_count kernel. Cannot be True if force_full_rank is True.</p></li>
<li><p><strong>G0</strong> (<em>Same as K0.</em>) – Same as K0. Provided for backwards compatibility. Cannot be given if K0 is given.</p></li>
<li><p><strong>G1</strong> (<em>Same as K1.</em>) – Same as K1. Provided for backwards compatibility. Cannot be given if K1 is given.</p></li>
<li><p><strong>runner</strong> – a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>, optional: Tells how to run locally, multi-processor, or on a cluster.
If not given, the function is run locally.</p></li>
<li><p><strong>pvalue_threshold</strong> (<em>number between 0 and 1</em>) – All output rows with p-values less than this threshold will be included. By default, all rows are included.
This is used to exclude rows with large p-values.</p></li>
<li><p><strong>random_threshold</strong> (<em>integer</em>) – All potential output rows are assigned a random value. All rows with a random value less than this threshold will be included.
By default, all rows are included. This is used to create a random sample of output rows.</p></li>
<li><p><strong>random_seed</strong> – Seed used to assign a random values to rows. Used with random_threshold.</p></li>
<li><p><strong>map_reduce_outer</strong> (<em>bool</em>) – If true (default), divides work by chromosome. If false, divides test_snp work into chunks.</p></li>
<li><p><strong>xp</strong> (<em>string</em><em> or </em><em>Python module</em>) – The array module to use (optional), for example, ‘numpy’ (normal CPU-based module)
or ‘cupy’ (GPU-based module). If not given, will try to read
from the ARRAY_MODULE environment variable. If not given and ARRAY_MODULE is not set,
will use numpy. If ‘cupy’ is requested, will
try to ‘import cupy’. If that import fails, will revert to numpy.
If two kernels are given, will ignore this and use ‘numpy’</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Python module</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>Pandas dataframe with one row per test SNP. Columns include “PValue”</p>
</dd>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">single_snp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.phe&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_snps</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.5chrom.*&quot;</span><span class="p">,</span><span class="s2">&quot;*.bed&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">single_snp</span><span class="p">(</span><span class="n">test_snps</span><span class="o">=</span><span class="n">test_snps</span><span class="p">,</span> <span class="n">pheno</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">,</span> <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">PValue</span><span class="p">,</span><span class="mi">7</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">))</span>
<span class="go">null_576 1e-07 10000</span>
</pre></div>
</div>
<p>For more examples, see:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://nbviewer.jupyter.org/github/fastlmm/FaST-LMM/blob/master/doc/ipynb/FaST-LMM.ipynb">Main FaST-LMM notebook</a></p></li>
<li><p><a class="reference external" href="https://nbviewer.jupyter.org/github/fastlmm/FaST-LMM/blob/master/doc/ipynb/fastlmm2021.ipynb">Multiple phenotypes and related new features</a></p></li>
</ul>
</dd></dl>

</div>
<div class="section" id="single-snp-scale">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_scale</span></code><a class="headerlink" href="#single-snp-scale" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.single_snp_scale">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">single_snp_scale</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">memory_factor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min_work_count</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gtg_runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gtg_min_work_count</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">svd_runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">postsvd_runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">postsvd_min_work_count</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">test_snps_runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">test_snps_min_work_count</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clear_local_lambda</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_python_only</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.single_snp_scale" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing single SNP GWAS using REML and cross validation over the chromosomes. Will reorder and intersect IIDs as needed.
It gives the same results as <a class="reference internal" href="#fastlmm.association.single_snp" title="fastlmm.association.single_snp"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp()</span></code></a> but scales a little better on a single machine and has the ability to run on a cluster. (Cluster
runs require appropriate modules for parameters <code class="docutils literal notranslate"><span class="pre">cache</span></code> and <code class="docutils literal notranslate"><span class="pre">runner</span></code>.)</p>
<p>To work with a G0 kernel larger than about 16K, requires a NumPy library that can do eigenvalue decompositions larger than 16K,
for example, one that uses MKL IPL64. Alternatively, use an older version of FaST-LMM (version 0.5.*) which includes its own version of MKL IPL64.</p>
<p>Compared to <a class="reference internal" href="#fastlmm.association.single_snp" title="fastlmm.association.single_snp"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp()</span></code></a>, <a class="reference internal" href="#fastlmm.association.single_snp_scale" title="fastlmm.association.single_snp_scale"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp_scale()</span></code></a> always:</p>
<ul class="simple">
<li><p>does cross validation of chromosomes (<a class="reference internal" href="#fastlmm.association.single_snp" title="fastlmm.association.single_snp"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp()</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">leave_out_one_chrom=True</span></code>)</p></li>
<li><p>use a low-rank kernel only (<a class="reference internal" href="#fastlmm.association.single_snp" title="fastlmm.association.single_snp"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp()</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">force_low_rank=True</span></code>)</p></li>
<li><p>uses exactly one kernel constructed from SNPs</p></li>
<li><p>searches for the best <code class="docutils literal notranslate"><span class="pre">h2</span></code>. (<a class="reference internal" href="#fastlmm.association.single_snp" title="fastlmm.association.single_snp"><code class="xref py py-func docutils literal notranslate"><span class="pre">single_snp()</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">h2=None</span></code>)</p></li>
</ul>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs to test. Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.
If you give a string, it should be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-bed">Bed</a>-formatted file.
For cluster runs, this and <code class="docutils literal notranslate"><span class="pre">G0</span></code> should be readable from any node on the cluster, for example, by using 
<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-distributedbed">DistributedBed</a> format.</p></li>
<li><p><strong>pheno</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – One or more phenotypes: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example,
<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a>, or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a>-formatted file.
If only one phenotype is given, any individual with missing phenotype data will be removed from processing.
If multiple phenotypes are given, any missing data will raise an error. (Avoid this by removing missing values, perhaps via filling in
missing values.)</p></li>
<li><p><strong>G0</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs from which to create a similarity matrix. Defaults to <code class="docutils literal notranslate"><span class="pre">test_snps</span></code>.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.
If you give a string, it should be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-bed">Bed</a>-formatted file.
For cluster runs, this and <code class="docutils literal notranslate"><span class="pre">test_snps</span></code> should be readable from any node on the cluster, for example, by using 
<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-distributedbed">DistributedBed</a> format.</p></li>
<li><p><strong>covar</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – covariate information, optional: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a>,
or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>,.
If you give a string, it should be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a>-formatted file. #!!!LATER raise error if has NaN</p></li>
<li><p><strong>cache</strong> (None or string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-filecache-filecache">FileCache</a> or dictionary from number to a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-filecache-filecache">FileCache</a>.) – Tells where to store intermediate results. Place the cache on an SSD drive for best performance.
By default, the cache will be an automatically-erasing temporary directory. (If the TEMP environment variable is set,
Python places the temporary directory under it.)
A string can be given and will be interpreted as the path of a local directory to use as a cache. (The local
directory will <strong>not</strong> be automatically erased and so must be user managed.) A <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-filecache-filecache">FileCache</a>
instance can be given, which provides a
method to specify a cluster-distributed cache. (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-filecache-filecache">FileCache</a>’s will <strong>not</strong> be automatically erased and must be user managed.)
Finally, a dictionary from 0 to 22 (inclusive) to <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-filecache-filecache">FileCache</a> (or None or string)
can be given. The dictionary specifies a cache for general work (0) and for every chromosome (1 to 22, inclusive).</p></li>
<li><p><strong>memory_factor</strong> (<em>number</em>) – How much memory to use proportional to <code class="docutils literal notranslate"><span class="pre">G0</span></code>, optional.
If not given, will assume that it can use memory about the same size as one copy of <code class="docutils literal notranslate"><span class="pre">G0</span></code>.</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created. The output format is tab-delimited text.</p></li>
<li><p><strong>runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>) – a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>, optional: Tells how to run locally, multi-processor, or on a cluster.
If not given, the function is run locally.</p></li>
<li><p><strong>min_work_count</strong> (<em>integer</em>) – When running the work on a cluster, the <strong>minimum</strong> number of pieces in which to divide the work. Defaults to 1, which is usually fine.</p></li>
<li><p><strong>gtg_runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>) – the <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a> to use instead of <code class="docutils literal notranslate"><span class="pre">runner</span></code> for the GtG stage of work.
For an overview of the stages, see below.</p></li>
<li><p><strong>gtg_min_work_count</strong> (<em>integer</em>) – the min_work_count to use instead of <code class="docutils literal notranslate"><span class="pre">min_work_count</span></code> on the GtG stage of work.</p></li>
<li><p><strong>svd_runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>) – the <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a> to use instead of <code class="docutils literal notranslate"><span class="pre">runner</span></code> for the SVD stage of work.</p></li>
<li><p><strong>postsvd_runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>.) – the <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a> to use instead of <code class="docutils literal notranslate"><span class="pre">runner</span></code> for the PostSVD stage of work.</p></li>
<li><p><strong>postsvd_min_work_count</strong> (<em>integer</em>) – the min_work_count to use instead of <code class="docutils literal notranslate"><span class="pre">min_work_count</span></code> on the PostSVD stage of work.</p></li>
<li><p><strong>test_snps_runner</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>.) – the <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a> to use instead of <code class="docutils literal notranslate"><span class="pre">runner</span></code> for the TestSNPS stage of work.</p></li>
<li><p><strong>test_snps_min_work_count</strong> (<em>integer</em>) – the min_work_count to use instead of <code class="docutils literal notranslate"><span class="pre">min_work_count</span></code> on the TestSNPS stage of work.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
<li><p><strong>clear_local_lambda</strong> (<em>function</em><em> or </em><em>lambda</em>) – A function to run in the middle of the PostSVD stage, typically to clear unneeded large files from the local file cache.</p></li>
<li><p><strong>force_python_only</strong> – (Default: False) Skip faster C++ code. Used for debugging and testing.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per test SNP. Columns include “PValue”</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">single_snp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_snps</span> <span class="o">=</span> <span class="n">Bed</span><span class="p">(</span><span class="n">example_file</span><span class="p">(</span><span class="s1">&#39;tests/datasets/synth/all.*&#39;</span><span class="p">,</span><span class="s1">&#39;*.bed&#39;</span><span class="p">),</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">True</span><span class="p">)[:,::</span><span class="mi">10</span><span class="p">]</span> <span class="c1">#use every 10th SNP</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;tests/datasets/synth/pheno_10_causals.txt&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cov_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;tests/datasets/synth/cov.txt&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">single_snp_scale</span><span class="p">(</span><span class="n">test_snps</span><span class="o">=</span><span class="n">test_snps</span><span class="p">,</span> <span class="n">pheno</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">,</span> <span class="n">covar</span><span class="o">=</span><span class="n">cov_fn</span><span class="p">,</span> <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">-etc-</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">PValue</span><span class="p">,</span><span class="mi">7</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">))</span>
<span class="go">snp1200_m0_.37m1_.36 0.0 500</span>
</pre></div>
</div>
<p>The stages of processing are:</p>
<ul class="simple">
<li><p>0: G - Read G0 (the selected SNPs), standardize, regress out covariates, output G</p></li>
<li><p>1: GtG - Compute GtG = G.T x G</p></li>
<li><p>2: SVD - For each chromosome in the TestSNPs, extract the GtG for the chromosome, compute the singular value decomposition (SVD) on that GtG</p></li>
<li><p>3: PostSVD - Transform the 22 GtG SVD into 22 G SVD results called U1 .. U22. Find h2, the importance of person-to-person similarity.</p></li>
<li><p>4: TestSNPs - For each test SNP, read its data, regress out covariates, use the appropriate U and compute a Pvalue.</p></li>
</ul>
<p>All stages cache intermediate results. If the results for stage are found in the cache, that stage will be skipped.</p>
</dd></dl>

</div>
<div class="section" id="single-snp-all-plus-select">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_all_plus_select</span></code><a class="headerlink" href="#single-snp-all-plus-select" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.single_snp_all_plus_select">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">single_snp_all_plus_select</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k_list</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_folds</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">GB_goal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_full_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_low_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mixing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">h2</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">do_plot</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.single_snp_all_plus_select" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing single SNP GWAS based on two kernels. The first kernel is based on all SNPs. The second kernel is a similarity matrix
constructed of the top <em>k</em> SNPs where the SNPs are ordered via the PValue from <code class="xref py py-meth docutils literal notranslate"><span class="pre">single_snp()</span></code> and <em>k</em> is determined via out-of-sample prediction.
All work is done via ‘leave_out_one_chrom’, that one chromosome is tested and the kernels are constructed from the other chromosomes.
Will reorder and intersect IIDs as needed.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> – <p>SNPs to test. Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, it should be the base name of a set of PLINK Bed-formatted files.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p>
</p></li>
<li><p><strong>pheno</strong> – <p>A single phenotype: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
Any IIDs with missing values will be removed.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p>
</p></li>
<li><p><strong>G</strong> – <p>SNPs from which to create a similarity matrix of the top <em>k</em> SNPs. If not given, will use test_snps.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, it should be the base name of a set of PLINK Bed-formatted files.</p>
</p></li>
<li><p><strong>covar</strong> – <p>covariate information, optional: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p>
</p></li>
<li><p><strong>k_list</strong> (<em>list of numbers</em>) – Values of <em>k</em> (in addition to 0) to test. Default to [1,2,4,8,…8192].</p></li>
<li><p><strong>n_folds</strong> (<em>number</em>) – Number of folds of cross validation to use for out-of-sample evaluation of various values of <em>k</em>. Default to 10.</p></li>
<li><p><strong>seed</strong> (<em>number</em>) – (optional) Random seed used to generate permutations for lrt G0 fitting.</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created.</p></li>
<li><p><strong>GB_goal</strong> (<em>number</em>) – gigabytes of memory the run should use, optional. If not given, will read the test_snps in blocks the same size as the kernel,
which is memory efficient with little overhead on computation time.</p></li>
<li><p><strong>force_full_rank</strong> (<em>Boolean</em>) – Even if kernels are defined with fewer SNPs than IIDs, create an explicit iid_count x iid_count kernel. Cannot be True if force_low_rank is True.</p></li>
<li><p><strong>force_low_rank</strong> (<em>Boolean</em>) – Even if kernels are defined with fewer IIDs than SNPs, create a low-rank iid_count x sid_count kernel. Cannot be True if force_full_rank is True.</p></li>
<li><p><strong>mixing</strong> (<em>number</em>) – A parameter to LMM learning telling how to combine the two kernels, optional
If not given will search for best value.</p></li>
<li><p><strong>h2</strong> (<em>number</em>) – A parameter to LMM learning that tells how much weight to give the K’s vs. the identity matrix, optional
If not given will search for best value.</p></li>
<li><p><strong>do_plot</strong> (<em>boolean</em>) – If true, will plot, for each chrom, the negative loglikelihood vs k.</p></li>
<li><p><strong>runner</strong> – <p>a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>, optional: Tells how to run locally, multi-processor, or on a cluster.
If not given, the function is run locally.</p>
</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per test SNP. Columns include “PValue”</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">single_snp_all_plus_select</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.util.mapreduce1.runner</span> <span class="kn">import</span> <span class="n">LocalMultiProc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.phe&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_snps</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.5chrom.*&quot;</span><span class="p">,</span><span class="s2">&quot;*.bed&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">snps</span> <span class="o">=</span> <span class="n">Bed</span><span class="p">(</span><span class="n">test_snps</span><span class="p">,</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)[:,::</span><span class="mi">100</span><span class="p">]</span> <span class="c1">#To make example faster, run on only 1/100th of the data</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">chrom5_snps</span> <span class="o">=</span> <span class="n">snps</span><span class="p">[:,</span><span class="n">snps</span><span class="o">.</span><span class="n">pos</span><span class="p">[:,</span><span class="mi">0</span><span class="p">]</span><span class="o">==</span><span class="mi">5</span><span class="p">]</span> <span class="c1"># Test on only chrom5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">single_snp_all_plus_select</span><span class="p">(</span><span class="n">test_snps</span><span class="o">=</span><span class="n">chrom5_snps</span><span class="p">,</span><span class="n">G</span><span class="o">=</span><span class="n">snps</span><span class="p">,</span><span class="n">pheno</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">,</span><span class="n">GB_goal</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">runner</span><span class="o">=</span><span class="n">LocalMultiProc</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><span class="n">mkl_num_threads</span><span class="o">=</span><span class="mi">5</span><span class="p">),</span> <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="c1">#Run multiproc</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">PValue</span><span class="p">,</span><span class="mi">7</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">))</span>
<span class="go">null_9800 0.0793385 4</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="single-snp-linreg">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_linreg</span></code><a class="headerlink" href="#single-snp-linreg" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.single_snp_linreg">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">single_snp_linreg</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_output_len</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">GB_goal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.single_snp_linreg" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing single SNP GWAS using linear regression. Will reorder and intersect IIDs as needed.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs to test. Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, it should be the base name of a set of PLINK Bed-formatted files.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>pheno</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – A single phenotype: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
Any IIDs with missing values will be removed.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>covar</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – covariate information, optional: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>max_output_len</strong> (<em>number</em>) – Maximum number of Pvalues to return. Default to None, which means ‘Return all’.</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created. The output format is tab-delimited text.</p></li>
<li><p><strong>GB_goal</strong> (<em>number</em>) – gigabytes of memory the run should use, optional. If not given, will read the test_snps in blocks of size iid_count,
which is memory efficient with little overhead on computation time.</p></li>
<li><p><strong>runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>) – <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>, optional: Tells how to run locally, multi-processor, or on a cluster.
If not given, the function is run locally.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per test SNP. Columns include “PValue”</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">single_snp_linreg</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.phe&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_snps</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.5chrom.*&quot;</span><span class="p">,</span><span class="s2">&quot;*.bed&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">single_snp_linreg</span><span class="p">(</span><span class="n">test_snps</span><span class="o">=</span><span class="n">test_snps</span><span class="p">,</span> <span class="n">pheno</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">,</span> <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">PValue</span><span class="p">,</span><span class="mi">7</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">))</span>
<span class="go">null_576 1e-07 10000</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="single-snp-select">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_select</span></code><a class="headerlink" href="#single-snp-select" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.single_snp_select">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">single_snp_select</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k_list</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_folds</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">just_return_selected_snps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">GB_goal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_full_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_low_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">h2</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.single_snp_select" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing single SNP GWAS based on covariates (often PCs) and a similarity matrix constructed of the top <em>k</em> SNPs where
SNPs are ordered via the PValue from <code class="xref py py-meth docutils literal notranslate"><span class="pre">single_snp_linreg()</span></code> and <em>k</em> is determined via out-of-sample prediction. Will reorder and intersect IIDs as needed.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs to test. Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, it should be the base name of a set of PLINK Bed-formatted files.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>pheno</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – A single phenotype: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
Any IIDs with missing values will be removed.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>G</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs from which to create a similarity matrix of the top <em>k</em> SNPs. If not given, will use test_snps.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, it should be the base name of a set of PLINK Bed-formatted files.</p></li>
<li><p><strong>covar</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – covariate information, optional: Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>, for example, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.
(For backwards compatibility can also be dictionary with keys ‘vals’, ‘iid’, ‘header’)</p></li>
<li><p><strong>k_list</strong> (<em>list of numbers</em>) – Values of <em>k</em> (in addition to 0) to test. Default to [1,2,4,8,…8192].</p></li>
<li><p><strong>n_folds</strong> (<em>number</em>) – Number of folds of cross validation to use for out-of-sample evaluation of various values of <em>k</em>. Default to 10.</p></li>
<li><p><strong>just_return_selected_snps</strong> (<em>list of strings</em>) – Instead of returning the results of GWAS, return the top <em>k</em> SNPs selected.</p></li>
<li><p><strong>seed</strong> (<em>number</em>) – (optional) Random seed used to generate permutations for lrt G0 fitting.</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created.</p></li>
<li><p><strong>GB_goal</strong> (<em>number</em>) – gigabytes of memory the run should use, optional. If not given, will read the test_snps in blocks the same size as the kernel,
which is memory efficient with little overhead on computation time.</p></li>
<li><p><strong>force_full_rank</strong> (<em>Boolean</em>) – Even if kernels are defined with fewer SNPs than IIDs, create an explicit iid_count x iid_count kernel. Cannot be True if force_low_rank is True.</p></li>
<li><p><strong>force_low_rank</strong> (<em>Boolean</em>) – Even if kernels are defined with fewer IIDs than SNPs, create a low-rank iid_count x sid_count kernel. Cannot be True if force_full_rank is True.</p></li>
<li><p><strong>h2</strong> (<em>number</em>) – A parameter to LMM learning that tells how much weight to give the K’s vs. the identity matrix, optional
If not given will search for best value.</p></li>
<li><p><strong>runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>) – a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>, optional: Tells how to run locally, multi-processor, or on a cluster.
If not given, the function is run locally.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per test SNP. Columns include “PValue”</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">single_snp_select</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">compute_auto_pcs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bed_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;tests/datasets/synth/all.bed&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">phen_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;tests/datasets/synth/pheno_10_causals.txt&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">covar</span> <span class="o">=</span> <span class="n">compute_auto_pcs</span><span class="p">(</span><span class="n">bed_fn</span><span class="p">,</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">single_snp_select</span><span class="p">(</span><span class="n">test_snps</span><span class="o">=</span><span class="n">bed_fn</span><span class="p">,</span> <span class="n">G</span><span class="o">=</span><span class="n">bed_fn</span><span class="p">,</span> <span class="n">pheno</span><span class="o">=</span><span class="n">phen_fn</span><span class="p">,</span> <span class="n">covar</span><span class="o">=</span><span class="n">covar</span><span class="p">,</span> <span class="n">GB_goal</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">PValue</span><span class="p">,</span><span class="mi">7</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">))</span>
<span class="go">snp495_m0_.01m1_.04 0.0 5000</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="epistasis">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">epistasis</span></code><a class="headerlink" href="#epistasis" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.epistasis">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">epistasis</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mixing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sid_list_0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sid_list_1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_delta</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min_log_delta</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-</span> <span class="pre">5</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_log_delta</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">runner</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.epistasis" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing epistasis GWAS.  See <a class="reference external" href="http://www.nature.com/srep/2013/130122/srep01099/full/srep01099.html">http://www.nature.com/srep/2013/130122/srep01099/full/srep01099.html</a>.
REML is used to optimize H2 and beta is always estimated via ML (maximum likelihood, see <a class="reference external" href="https://static-content.springer.com/esm/art%3A10.1038%2Fnmeth.1681/MediaObjects/41592_2011_BFnmeth1681_MOESM290_ESM.pdf">https://static-content.springer.com/esm/art%3A10.1038%2Fnmeth.1681/MediaObjects/41592_2011_BFnmeth1681_MOESM290_ESM.pdf</a>).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs from which to test pairs. If you give a string, it should be the base name of a set of PLINK Bed-formatted files.</p></li>
<li><p><strong>pheno</strong> (<em>a 'pheno dictionary'</em><em> or </em><em>a string</em>) – A single phenotype: A ‘pheno dictionary’ contains an ndarray on the ‘vals’ key and a iid list on the ‘iid’ key.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>G0</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs from which to construct a similarity matrix.
If you give a string, it should be the base name of a set of PLINK Bed-formatted files.</p></li>
<li><p><strong>G1</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs from which to construct a second similarity kernel, optional. Also, see ‘mixing’).
If you give a string, it should be the base name of a set of PLINK Bed-formatted files.</p></li>
<li><p><strong>mixing</strong> (<em>number</em>) – Weight between 0.0 (inclusive, default) and 1.0 (inclusive) given to G1 relative to G0.
If you give no mixing number, G0 will get all the weight and G1 will be ignored.</p></li>
<li><p><strong>covar</strong> (<em>a 'pheno dictionary'</em><em> or </em><em>a string</em>) – covariate information, optional: A ‘pheno dictionary’ contains an ndarray on the ‘vals’ key and a iid list on the ‘iid’ key.
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>sid_list_0</strong> (<em>list of strings</em>) – list of sids, optional:
All unique pairs from sid_list_0 x sid_list_1 will be evaluated.
If you give no sid_list_0, all sids in test_snps will be used.</p></li>
<li><p><strong>sid_list_1</strong> (<em>list of strings</em>) – list of sids, optional:
All unique pairs from sid_list_0 x sid_list_1 will be evaluated.
If you give no sid_list_1, all sids in test_snps will be used.</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created. The output format is tab-delimited text.</p></li>
<li><p><strong>log_delta</strong> (<em>number</em>) – A parameter to LMM learning, optional
If not given will search for best value.</p></li>
<li><p><strong>min_log_delta</strong> (<em>number</em>) – (default:-5)
When searching for log_delta, the lower bounds of the search.</p></li>
<li><p><strong>max_log_delta</strong> (<em>number</em>) – (default:-5)
When searching for log_delta, the upper bounds of the search.</p></li>
<li><p><strong>cache_file</strong> (<em>file name</em>) – Name of  file to read or write cached precomputation values to, optional.
If not given, no cache file will be used.
If given and file does not exists, will write precomputation values to file.
If given and file does exists, will read precomputation values from file.
The file contains the U and S matrix from the decomposition of the training matrix. It is in Python’s np.savez (*.npz) format.
Calls using the same cache file should have the same ‘G0’ and ‘G1’</p></li>
<li><p><strong>runner</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>) – a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#util-mapreduce1-runner-runner">Runner</a>, optional: Tells how to run locally, multi-processor, or on a cluster.
If not given, the function is run locally.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per SNP pair. Columns include “PValue”</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">epistasis</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">bed_file</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s1">&#39;tests/datasets/all_chr.maf0.001.N300.*&#39;</span><span class="p">,</span><span class="s1">&#39;*.bed&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_snps</span> <span class="o">=</span> <span class="n">Bed</span><span class="p">(</span><span class="n">bed_file</span><span class="p">,</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s1">&#39;tests/datasets/phenSynthFrom22.23.N300.randcidorder.txt&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">covar</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s1">&#39;tests/datasets/all_chr.maf0.001.covariates.N300.txt&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">epistasis</span><span class="p">(</span><span class="n">test_snps</span><span class="p">,</span> <span class="n">pheno</span><span class="p">,</span> <span class="n">G0</span><span class="o">=</span><span class="n">test_snps</span><span class="p">,</span> <span class="n">covar</span><span class="o">=</span><span class="n">covar</span><span class="p">,</span> 
<span class="gp">... </span>                                <span class="n">sid_list_0</span><span class="o">=</span><span class="n">test_snps</span><span class="o">.</span><span class="n">sid</span><span class="p">[:</span><span class="mi">10</span><span class="p">],</span> <span class="c1">#first 10 snps</span>
<span class="gp">... </span>                                <span class="n">sid_list_1</span><span class="o">=</span><span class="n">test_snps</span><span class="o">.</span><span class="n">sid</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">15</span><span class="p">],</span> <span class="c1">#Skip 5 snps, use next 10</span>
<span class="gp">... </span>                                <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP0</span><span class="p">,</span> <span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SNP1</span><span class="p">,</span><span class="nb">round</span><span class="p">(</span><span class="n">results_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">PValue</span><span class="p">,</span><span class="mi">5</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">))</span>
<span class="go">1_12 1_9 0.07779 85</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="snp-set">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">snp_set</span></code><a class="headerlink" href="#snp-set" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.snp_set">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">snp_set</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">test_snps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">set_list</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pheno</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'lrt'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">write_lrtperm</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nperm</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">npermabs</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mpheno</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">G0_fit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'qq'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">qmax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">minsetsize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxsetsize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mindist</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">idist</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_pvalue_5050</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.snp_set" title="Permalink to this definition">¶</a></dt>
<dd><p>Function performing GWAS on sets of snps</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>test_snps</strong> (<em>a string</em>) – The base name of the file containing the SNPs for alternative kernel. The file must be in PLINK Bed format.</p></li>
<li><p><strong>set_list</strong> (<em>a string</em>) – The name of a tab-delimited file defining the sets. The file should contain two-columns ‘snp’ and ‘set’.</p></li>
<li><p><strong>pheno</strong> (<em>a string</em>) – The name of a file containing the phenotype. The file must be in PLINK phenotype format.</p></li>
<li><p><strong>covar</strong> (<em>a 'pheno dictionary'</em><em> or </em><em>a string</em>) – covariate information, optional: The name of a file in PLINK phenotype format.</p></li>
<li><p><strong>output_file_name</strong> (<em>file name</em>) – Name of file to write results to, optional. If not given, no output file will be created.</p></li>
<li><p><strong>G0</strong> (<em>a string</em>) – Training SNPs from which to construct a similarity kernel. It should be the base name of files in PLINK Bed or Ped format.</p></li>
<li><p><strong>test</strong> (<em>a string</em>) – ‘lrt’ (default) or ‘sc_davies’</p></li>
<li><p><strong>write_lrtperm</strong> (<em>boolean</em>) – (default: False) If True, write the lrtperm vector (dictated by seed) to a file.</p></li>
<li><p><strong>nperm</strong> (<em>number</em>) – (default: 10) number of permutations per test</p></li>
<li><p><strong>npermabs</strong> (<em>number</em>) – (default: None) absolute number of permutations</p></li>
<li><p><strong>mpheno</strong> (<em>number</em>) – (default: 1) integer, starting at 1, representing the index of the phenotype tested</p></li>
<li><p><strong>G0_fit</strong> (<em>string</em>) – (default: “qq”) How to fit G0. Should be either “qq” or “ml”</p></li>
<li><p><strong>qmax</strong> (<em>number</em>) – (default: .1) Use the top qmax fraction of G0 distrib test statistics to fit the G0 distribution</p></li>
<li><p><strong>seed</strong> (<em>number</em>) – (optional) Random seed used to generate permutations for lrt G0 fitting.</p></li>
<li><p><strong>minsetsize</strong> (<em>number</em>) – (optional) only include sets at least this large (inclusive)</p></li>
<li><p><strong>maxsetsize</strong> (<em>number</em>) – (optional) only include sets no more than this large (inclusive)</p></li>
<li><p><strong>mindist</strong> (<em>number</em>) – (default 0) SNPs within mindist from the test SNPs will be removed from</p></li>
<li><p><strong>idist</strong> (<em>number</em>) – (default: 1) the type of position to use with mindist
1, genomic distance
2, base-pair distance</p></li>
<li><p><strong>show_pvalue_5050</strong> (<em>Boolean</em>) – (default: False) show a conservative P-value arising from an assumed null distribution that is a 50-50 mixture distribution of 0 and 1 dof chi squares [Molenberghs and Verbeke, 2003].
Provided for backwards compatibility.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per set.</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">snp_set</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result_dataframe</span> <span class="o">=</span> <span class="n">snp_set</span><span class="p">(</span>
<span class="gp">... </span>    <span class="n">test_snps</span> <span class="o">=</span> <span class="s1">&#39;../../tests/datasets/all_chr.maf0.001.N300&#39;</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">set_list</span> <span class="o">=</span> <span class="s1">&#39;../../tests/datasets/set_input.23.txt&#39;</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">pheno</span> <span class="o">=</span> <span class="s1">&#39;../../tests/datasets/phenSynthFrom22.23.N300.txt&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">result_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">SetId</span><span class="p">,</span> <span class="nb">round</span><span class="p">(</span><span class="n">result_dataframe</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;P-value&#39;</span><span class="p">],</span><span class="mi">15</span><span class="p">))</span>
<span class="go">set23 0.0</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="fastlmm">
<h2><code class="xref py py-class docutils literal notranslate"><span class="pre">FastLMM</span></code><a class="headerlink" href="#fastlmm" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="fastlmm.inference.FastLMM">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">fastlmm.inference.</span></span><span class="sig-name descname"><span class="pre">FastLMM</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">GB_goal</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_full_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force_low_rank</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">snp_standardizer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">Unit()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">covariate_standardizer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">Unit()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kernel_standardizer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">DiagKtoN()</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.FastLMM" title="Permalink to this definition">¶</a></dt>
<dd><p>A predictor, somewhat in the style of scikit-learn, for learning and predicting with linear mixed models.</p>
<dl>
<dt><strong>Constructor:</strong></dt><dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>GB_goal</strong> (int) – gigabytes of memory the run should use, optional. If not given, will read the test_snps in blocks the same size as the kernel, which is memory efficient with little overhead on computation time.</p></li>
<li><p><strong>force_full_rank</strong> (bool) – Even if kernels are defined with fewer SNPs than IIDs, create an explicit iid_count x iid_count kernel. Cannot be True if force_low_rank is True.</p></li>
<li><p><strong>force_low_rank</strong> (bool) – Even if kernels are defined with fewer IIDs than SNPs, create a low-rank iid_count x sid_count kernel. Cannot be True if force_full_rank is True.</p></li>
<li><p><strong>snp_standardizer</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer</span></code>) – The PySnpTools standardizer to be apply to SNP data. Choices include <code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer.Unit</span></code> (Default. Makes values for each SNP have mean zero and standard deviation 1.0, then fills missing with zero) and <code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer.Identity</span></code> (Do nothing)</p></li>
<li><p><strong>covariate_standardizer</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer</span></code>) – The PySnpTools standardizer to be apply to X, the covariate data. Some choices include <code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer.Unit</span></code> (Default. Fills missing with zero) and <code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer.Identity</span></code> (do nothing)</p></li>
<li><p><strong>kernel_standardizer</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">KernelStandardizer</span></code>) – The PySnpTools kernel standardizer to be apply to the kernels. Some choices include <code class="xref py py-class docutils literal notranslate"><span class="pre">KernelStandardizer.DiagKToN</span></code> (Default. Make the diagonal sum to iid_count)  and <code class="xref py py-class docutils literal notranslate"><span class="pre">KernelStandardizer.Identity</span></code> (Do nothing)</p></li>
</ul>
</dd>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span><span class="p">,</span> <span class="n">Pheno</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.inference</span> <span class="kn">import</span> <span class="n">FastLMM</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">snpreader</span> <span class="o">=</span> <span class="n">Bed</span><span class="p">(</span><span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.5chrom.*&quot;</span><span class="p">,</span><span class="s2">&quot;*.bed&quot;</span><span class="p">),</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cov_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.cov&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.phe&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_idx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">r_</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="n">snpreader</span><span class="o">.</span><span class="n">iid_count</span><span class="p">]</span> <span class="c1"># iids 10 and on</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_idx</span>  <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">r_</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="c1"># the first 10 iids</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fastlmm</span> <span class="o">=</span> <span class="n">FastLMM</span><span class="p">(</span><span class="n">GB_goal</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#We give it phenotype and covariate information for extra examples, but it reorders and intersects the examples, so only training examples are used. </span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">=</span> <span class="n">fastlmm</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">K0_train</span><span class="o">=</span><span class="n">snpreader</span><span class="p">[</span><span class="n">train_idx</span><span class="p">,:],</span><span class="n">X</span><span class="o">=</span><span class="n">cov_fn</span><span class="p">,</span><span class="n">y</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">)</span> 
<span class="gp">&gt;&gt;&gt; </span><span class="n">mean</span><span class="p">,</span> <span class="n">covariance</span> <span class="o">=</span> <span class="n">fastlmm</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">K0_whole_test</span><span class="o">=</span><span class="n">snpreader</span><span class="p">[</span><span class="n">test_idx</span><span class="p">,:],</span><span class="n">X</span><span class="o">=</span><span class="n">cov_fn</span><span class="p">,</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">mean</span><span class="o">.</span><span class="n">iid</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">round</span><span class="p">(</span><span class="n">mean</span><span class="o">.</span><span class="n">val</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span><span class="mi">7</span><span class="p">),</span> <span class="nb">round</span><span class="p">(</span><span class="n">covariance</span><span class="o">.</span><span class="n">val</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span><span class="mi">7</span><span class="p">))</span>
<span class="go">[&#39;per0&#39;, &#39;per0&#39;] 0.1791958 0.8995209</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nll</span> <span class="o">=</span> <span class="n">fastlmm</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">K0_whole_test</span><span class="o">=</span><span class="n">snpreader</span><span class="p">[</span><span class="n">test_idx</span><span class="p">,:],</span><span class="n">X</span><span class="o">=</span><span class="n">cov_fn</span><span class="p">,</span><span class="n">y</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">,</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">nll</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
<span class="go">13.462323</span>
</pre></div>
</div>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="fastlmm.inference.FastLMM.fit">
<span class="sig-name descname"><span class="pre">fit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0_train</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1_train</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">h2raw</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mixing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.FastLMM.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Method for training a <a class="reference internal" href="#fastlmm.inference.FastLMM" title="fastlmm.inference.FastLMM"><code class="xref py py-class docutils literal notranslate"><span class="pre">FastLMM</span></code></a> predictor. If the examples in X, y, K0_train, K1_train are not the same, they will be reordered and intersected.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>
(such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – training covariate information, optional: 
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>y</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> 
(such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – training phenotype:
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>K0_train</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or
<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – A similarity matrix or SNPs from which to construct such a similarity matrix.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.
If you give a string, can be the name of a PLINK-formated Bed file.
Can be PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>.
If you give a string it can be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a> file.</p></li>
<li><p><strong>K1_train</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or
<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – A second similarity matrix or SNPs from which to construct such a second similarity matrix. (Also, see ‘mixing’).
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, can be the name of a PLINK-formated Bed file.
Can be PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>.
If you give a string it can be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a> file.</p></li>
<li><p><strong>h2raw</strong> (<em>number</em>) – A parameter to LMM learning that tells how much weight to give the K’s vs. the identity matrix, optional 
If not given will search for best value.
If mixing is unspecified, then h2 must also be unspecified.</p></li>
<li><p><strong>mixing</strong> (<em>number</em>) – Weight between 0.0 (inclusive, default) and 1.0 (inclusive) given to K1_train relative to K0_train.
If you give no mixing number and a K1_train is given, the best weight will be learned.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>self, the fitted FastLMM predictor</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="fastlmm.inference.FastLMM.predict">
<span class="sig-name descname"><span class="pre">predict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iid_if_none</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.FastLMM.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Method for predicting from a fitted <a class="reference internal" href="#fastlmm.inference.FastLMM" title="fastlmm.inference.FastLMM"><code class="xref py py-class docutils literal notranslate"><span class="pre">FastLMM</span></code></a> predictor.
If the examples in X, K0_whole_test, K1_whole_test are not the same, they will be reordered and intersected.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – testing covariate information, optional: 
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>K0_whole_test</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – A similarity matrix from all the examples to the test examples. Alternatively,
the test SNPs needed to construct such a similarity matrix.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, can be the name of a PLINK-formated Bed file.
Can be PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>. If you give a string it can be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a> file.</p></li>
<li><p><strong>K1_whole_test</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – A second similarity matrix from all the examples to the test examples. Alternatively,
the test SNPs needed to construct such a similarity matrix.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, can be the name of a PLINK-formated Bed file.
Can be PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>. If you give a string it can be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a> file.</p></li>
<li><p><strong>iid_if_none</strong> (<em>an ndarray of two strings</em>) – Examples to predict for if no X, K0_whole_test, K1_whole_test is provided.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>A <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a> of the means and a <code class="xref py py-class docutils literal notranslate"><span class="pre">KernelData</span></code> of the covariance</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="fastlmm.inference.FastLMM.score">
<span class="sig-name descname"><span class="pre">score</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iid_if_none</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">return_mse_too</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">return_per_iid</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.FastLMM.score" title="Permalink to this definition">¶</a></dt>
<dd><p>Method for calculating the negative log likelihood of testing examples.
If the examples in X,y,  K0_whole_test, K1_whole_test are not the same, they will be reordered and intersected.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – testing covariate information, optional: 
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>y</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – testing phenotype:
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>K0_whole_test</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – A similarity matrix from all the examples to the test examples. Alternatively,
the test SNPs needed to construct such a similarity matrix.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, can be the name of a PLINK-formated Bed file.
Can be PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>. If you give a string it can be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a> file.</p></li>
<li><p><strong>K1_whole_test</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – A second similarity matrix from all the examples to the test examples. Alternatively,
the test SNPs needed to construct such a similarity matrix.
Can be any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>. If you give a string, can be the name of a PLINK-formated Bed file.
Can be PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>. If you give a string it can be the name of a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelnpz">KernelNpz</a> file.</p></li>
<li><p><strong>iid_if_none</strong> (<em>an ndarray of two strings</em>) – Examples to predict for if no X, K0_whole_test, K1_whole_test is provided.</p></li>
<li><p><strong>return_mse_too</strong> (<em>bool</em>) – If true, will also return the mean squared error.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
<li><p><strong>count_A1</strong> – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>a float of the negative log likelihood and, optionally, a float of the mean squared error.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="linearregression">
<h2><code class="xref py py-class docutils literal notranslate"><span class="pre">LinearRegression</span></code><a class="headerlink" href="#linearregression" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="fastlmm.inference.LinearRegression">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">fastlmm.inference.</span></span><span class="sig-name descname"><span class="pre">LinearRegression</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">covariate_standardizer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">Unit()</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.LinearRegression" title="Permalink to this definition">¶</a></dt>
<dd><p>A linear regression predictor, that works like the FastLMM in fastlmm_predictor.py, but that expects all similarity matrices to be identity.</p>
<dl>
<dt><strong>Constructor:</strong></dt><dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>covariate_standardizer</strong> (<code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer</span></code>) – The PySnpTools standardizer to be apply to X, the covariate data. Some choices include <code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer.Unit</span></code> (Default. Fills missing with zero) and <code class="xref py py-class docutils literal notranslate"><span class="pre">Standardizer.Identity</span></code> (do nothing)</p></li>
</ul>
</dd>
<dt class="field-even">Example</dt>
<dd class="field-even"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Pheno</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.inference</span> <span class="kn">import</span> <span class="n">LinearRegression</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cov</span> <span class="o">=</span> <span class="n">Pheno</span><span class="p">(</span><span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.cov&quot;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.phe&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">train_idx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">r_</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="n">cov</span><span class="o">.</span><span class="n">iid_count</span><span class="p">]</span> <span class="c1"># iids 10 and on</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_idx</span>  <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">r_</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="c1"># the first 10 iids</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">linreg</span> <span class="o">=</span> <span class="n">LinearRegression</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#We give it phenotype information for extra examples, but it reorders and intersects the examples, so only training examples are used. </span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">_</span> <span class="o">=</span> <span class="n">linreg</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="o">=</span><span class="n">cov</span><span class="p">[</span><span class="n">train_idx</span><span class="p">,:],</span><span class="n">y</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">)</span> 
<span class="gp">&gt;&gt;&gt; </span><span class="n">mean</span><span class="p">,</span> <span class="n">covariance</span> <span class="o">=</span> <span class="n">linreg</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X</span><span class="o">=</span><span class="n">cov</span><span class="p">[</span><span class="n">test_idx</span><span class="p">,:])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">mean</span><span class="o">.</span><span class="n">iid</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">round</span><span class="p">(</span><span class="n">mean</span><span class="o">.</span><span class="n">val</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span><span class="mi">7</span><span class="p">),</span> <span class="nb">round</span><span class="p">(</span><span class="n">covariance</span><span class="o">.</span><span class="n">val</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">],</span><span class="mi">7</span><span class="p">))</span>
<span class="go">[&#39;per0&#39; &#39;per0&#39;] 0.1518764 0.9043703</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">nll</span> <span class="o">=</span> <span class="n">linreg</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X</span><span class="o">=</span><span class="n">cov</span><span class="p">[</span><span class="n">test_idx</span><span class="p">,:],</span><span class="n">y</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">nll</span><span class="p">,</span><span class="mi">6</span><span class="p">))</span>
<span class="go">13.668845</span>
</pre></div>
</div>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="fastlmm.inference.LinearRegression.fit">
<span class="sig-name descname"><span class="pre">fit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0_train</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1_train</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">h2</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mixing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.LinearRegression.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Method for training a <a class="reference internal" href="#fastlmm.inference.FastLMM" title="fastlmm.inference.FastLMM"><code class="xref py py-class docutils literal notranslate"><span class="pre">FastLMM</span></code></a> predictor. If the examples in X, y, K0_train, K1_train are not the same, they will be reordered and intersected.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – training covariate information, optional: 
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>y</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – training phenotype:
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>K0_train</strong> (<em>None</em>) – Must be None. Represents the identity similarity matrix.</p></li>
<li><p><strong>K1_train</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – Must be None. Represents the identity similarity matrix.</p></li>
<li><p><strong>h2</strong> (<em>number</em>) – Ignored. Optional.</p></li>
<li><p><strong>mixing</strong> (<em>number</em>) – Ignored. Optional.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>self, the fitted Linear Regression predictor</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="fastlmm.inference.LinearRegression.predict">
<span class="sig-name descname"><span class="pre">predict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iid_if_none</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.LinearRegression.predict" title="Permalink to this definition">¶</a></dt>
<dd><p>Method for predicting from a fitted <a class="reference internal" href="#fastlmm.inference.FastLMM" title="fastlmm.inference.FastLMM"><code class="xref py py-class docutils literal notranslate"><span class="pre">FastLMM</span></code></a> predictor.
If the examples in X, K0_whole_test, K1_whole_test are not the same, they will be reordered and intersected.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – testing covariate information, optional: 
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>K0_whole_test</strong> (<em>None</em>) – Must be None. Represents the identity similarity matrix.</p></li>
<li><p><strong>K1_whole_test</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – Must be None. Represents the identity similarity matrix.</p></li>
<li><p><strong>iid_if_none</strong> (<em>an ndarray of two strings</em>) – Examples to predict for if no X, K0_whole_test, K1_whole_test is provided.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>A <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a> of the means and a <code class="xref py py-class docutils literal notranslate"><span class="pre">KernelData</span></code> of the covariance</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="fastlmm.inference.LinearRegression.score">
<span class="sig-name descname"><span class="pre">score</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">y</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K0_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K1_whole_test</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iid_if_none</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">return_mse_too</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.inference.LinearRegression.score" title="Permalink to this definition">¶</a></dt>
<dd><p>Method for calculating the negative log likelihood of testing examples.
If the examples in X,y,  K0_whole_test, K1_whole_test are not the same, they will be reordered and intersected.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – testing covariate information, optional: 
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>y</strong> (a PySnpTools <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> (such as <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpdata">SnpData</a>) or string.) – testing phenotype:
If you give a string, it should be the file name of a PLINK phenotype-formatted file.</p></li>
<li><p><strong>K0_whole_test</strong> (<em>None</em>) – Must be None. Represents the identity similarity matrix.</p></li>
<li><p><strong>K1_whole_test</strong> (<a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string or <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>) – Must be None. Represents the identity similarity matrix.</p></li>
<li><p><strong>iid_if_none</strong> (<em>an ndarray of two strings</em>) – Examples to predict for if no X, K0_whole_test, K1_whole_test is provided.</p></li>
<li><p><strong>return_mse_too</strong> (<em>bool</em>) – If true, will also return the mean squared error.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>a float of the negative log likelihood and, optionally, a float of the mean squared error.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="heritability-spatial-correction">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">heritability_spatial_correction</span></code><a class="headerlink" href="#heritability-spatial-correction" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.association.heritability_spatial_correction">
<span class="sig-prename descclassname"><span class="pre">fastlmm.association.</span></span><span class="sig-name descname"><span class="pre">heritability_spatial_correction</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">G_kernel</span></em>, <em class="sig-param"><span class="pre">spatial_coor</span></em>, <em class="sig-param"><span class="pre">spatial_iid</span></em>, <em class="sig-param"><span class="pre">alpha_list</span></em>, <em class="sig-param"><span class="pre">alpha_power</span></em>, <em class="sig-param"><span class="pre">pheno</span></em>, <em class="sig-param"><span class="pre">map_function=&lt;class</span> <span class="pre">'map'&gt;</span></em>, <em class="sig-param"><span class="pre">cache_folder=None</span></em>, <em class="sig-param"><span class="pre">jackknife_count=500</span></em>, <em class="sig-param"><span class="pre">permute_plus_count=10000</span></em>, <em class="sig-param"><span class="pre">permute_times_count=10000</span></em>, <em class="sig-param"><span class="pre">seed=0</span></em>, <em class="sig-param"><span class="pre">just_testing=False</span></em>, <em class="sig-param"><span class="pre">always_remote=False</span></em>, <em class="sig-param"><span class="pre">allow_gxe2=True</span></em>, <em class="sig-param"><span class="pre">count_A1=None</span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.association.heritability_spatial_correction" title="Permalink to this definition">¶</a></dt>
<dd><p>Function measuring heritability with correction for spatial location.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>G_kernel</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#kernelreader-kernelreader">KernelReader</a>, <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – A kernel that tells the genetic similarity between all pairs of individuals. The kernel can be given 
explicitly, for example with a <code class="xref py py-class docutils literal notranslate"><span class="pre">KernelData</span></code>. The kernel can also be given implicitly by providing a set of
SNPs or the name of a BED file.</p></li>
<li><p><strong>spatial_coor</strong> (<em>a iid_count x 2 array</em>) – The position of each individual given by two coordinates. Any units are allowed, but the two values
must be compatible so that distance can be determined via Pythagoras’ theorem. (So, longitude and latitude should
not be used unless the locations are near the Equator.)</p></li>
<li><p><strong>spatial_iid</strong> (<em>array of strings with shape</em><em> [</em><em>iid_count</em><em>,</em><em>2</em><em>]</em>) – A ndarray of the iids. Each iid is a ndarray of two strings (a family ID and a case ID) that identifies an individual.</p></li>
<li><p><strong>alpha_list</strong> (<em>number</em>) – a list of numbers to search to find the best alpha, which is the similarity scale. The similarity of two individuals
is here defined as exp(-(distance_between/alpha)**alpha_power). If the closest individuals are 100 units apart and the farthest
individuals are 4e6 units apart, a reasonable alpha_list might be: [int(v) for v in np.logspace(np.log10(100),np.log10(1e10), 100)]
The function’s reports on the alphas chosen. If an extreme alpha is picked, change alpha_list to cover more range.</p></li>
<li><p><strong>alpha_power</strong> – 2 (a good choice) means that similarity goes with area. 1 means with distance.</p></li>
<li><p><strong>pheno</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or string) – The target values(s) to predict. It can be a file name readable via <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-pheno">Pheno</a> or any <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a>.</p></li>
<li><p><strong>cache_folder</strong> (<em>a string</em>) – (default ‘None’) The name of a directory in which to save intermediate results. If ‘None’, then no intermediate results are saved.</p></li>
<li><p><strong>map_function</strong> (<em>a function</em>) – (default ‘map’) A function with the same inputs and functionality as Python’s ‘map’ function.
Can be used to run ‘heritability_spatial_correction’ on a cluster.</p></li>
<li><p><strong>jackknife_count</strong> (<em>number</em>) – (default 500) The number of jackknife groups to use when calculating standard errors (SE). Changing to a small number, 2, 
speeds up calculation at the cost of unusable SEs.</p></li>
<li><p><strong>permute_plus_count</strong> (<em>number</em>) – (default 10000) The number of permutations used when calculating P values. Changing to a small number, 1, 
speeds up calculation at the cost of unusable P values.</p></li>
<li><p><strong>permute_times_count</strong> (<em>number</em>) – (default 10000) The number of permutations used when calculating P values. Changing to a small number, 1, 
speeds up calculation at the cost of unusable P values.</p></li>
<li><p><strong>seed</strong> (<em>number</em>) – (default 0) The random seed used by jackknifing and permutation.</p></li>
<li><p><strong>just_testing</strong> (<em>bool</em>) – (default False) If true, skips actual LMM-related search and calculation.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>Pandas dataframe with one row per phenotype. Columns include “h2uncorr”, “h2corr”, etc.</p>
</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="util-module">
<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">util</span></code> Module<a class="headerlink" href="#util-module" title="Permalink to this headline">¶</a></h2>
<div class="section" id="util-compute-auto-pcs">
<h3><code class="xref py py-mod docutils literal notranslate"><span class="pre">util.compute_auto_pcs</span></code><a class="headerlink" href="#util-compute-auto-pcs" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.util.compute_auto_pcs">
<span class="sig-prename descclassname"><span class="pre">fastlmm.util.</span></span><span class="sig-name descname"><span class="pre">compute_auto_pcs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">snpreader</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cutoff</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k_values</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">array([0,</span> <span class="pre">1,</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4,</span> <span class="pre">5,</span> <span class="pre">6,</span> <span class="pre">7,</span> <span class="pre">8,</span> <span class="pre">9,</span> <span class="pre">10])</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output_file_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">count_A1</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.util.compute_auto_pcs" title="Permalink to this definition">¶</a></dt>
<dd><p>Function automatically finds the best principle components (PCs)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>snpreader</strong> (a <a class="reference external" href="http://fastlmm.github.io/PySnpTools/#snpreader-snpreader">SnpReader</a> or a string) – SNPs for which to find the best PCs
If you give a string, it should be the base name of a set of PLINK Bed-formatted files.</p></li>
<li><p><strong>cutoff</strong> (<em>a number between 0 and 1.</em>) – (default: .1) The degree of relatedness to remove before finding the best number of PCs.
Relatedness is measured with a RRM (realized relationship matrix) so 0 is no relation, .5 is a sibling or parent, and 1 is self or twin.</p></li>
<li><p><strong>k_values</strong> (<em>list of integers</em>) – (default: 0 … 10 [inclusive]) The number of PCs to search.</p></li>
<li><p><strong>count_A1</strong> (<em>bool</em>) – If it needs to read SNP data from a BED-formatted file, tells if it should count the number of A1
alleles (the PLINK standard) or the number of A2 alleles. False is the current default, but in the future the default will change to True.</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>A phenotype dictionary with property ‘iid’ listing the iids and property ‘vals’ containing a nparray of PC values.</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><p></p></dd>
</dl>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">compute_auto_pcs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">file_name</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.5chrom.*&quot;</span><span class="p">,</span><span class="s2">&quot;*.bed&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">best_pcs</span> <span class="o">=</span> <span class="n">compute_auto_pcs</span><span class="p">(</span><span class="n">file_name</span><span class="p">,</span><span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">best_pcs</span><span class="p">[</span><span class="s1">&#39;vals&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span><span class="nb">int</span><span class="p">(</span><span class="n">best_pcs</span><span class="p">[</span><span class="s1">&#39;vals&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
<span class="go">500 0</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="util-manhattan-plot">
<h3><code class="xref py py-mod docutils literal notranslate"><span class="pre">util.manhattan_plot</span></code><a class="headerlink" href="#util-manhattan-plot" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="fastlmm.util.manhattan_plot">
<span class="sig-prename descclassname"><span class="pre">fastlmm.util.</span></span><span class="sig-name descname"><span class="pre">manhattan_plot</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">chr_pos_pvalue_array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pvalue_line</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">plot_threshold</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">vline_significant</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">marker</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'o'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">chromosome_starts</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xaxis_unit_bp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alpha</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fastlmm.util.manhattan_plot" title="Permalink to this definition">¶</a></dt>
<dd><p>Function to create a Manhattan plot.  See <a class="reference external" href="http://en.wikipedia.org/wiki/Manhattan_plot">http://en.wikipedia.org/wiki/Manhattan_plot</a>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>chr_pos_pvalue_array</strong> (<em>numpy array</em>) – an n x 3 numpy array. The three columns are the chrom number 
(as a number), the position, and pvalue.</p></li>
<li><p><strong>pvalue_line</strong> (<em>number</em>) – (Default: None). If given, draws a line at that PValue.</p></li>
<li><p><strong>plot_threshold</strong> (<em>number</em>) – (Default: 1) Plot only SNPs that achieve a P-value smaller than pvalue_threshold
to speed up plotting</p></li>
<li><p><strong>vline_significant</strong> (<em>Boolean</em>) – If true, draw a vertical line at each significant Pvalue (Default: False)</p></li>
<li><p><strong>marker</strong> (<em>string</em>) – marker for the scatter plot. default: “o”</p></li>
<li><p><strong>chromosome_starts</strong> (<em>[</em><em>Nchrom x 3</em><em>] </em><em>ndarray</em>) – chromosome, cumulative start position, cumulative stop position
cumulative chromosome starts, for plotting. If None (default), this is estimated from data</p></li>
<li><p><strong>xaxis_unit_bp</strong> (<em>Boolean</em>) – If true, plot cumulative position in basepair units on x axis. If False, only 
use rank of SNP positions. (default: True)</p></li>
<li><p><strong>alpha</strong> (<em>number</em>) – alpha (opaqueness) for P-value markers in scatterplot (default 0.5)</p></li>
</ul>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>chromosome_starts       [Nchrom x 3] ndarray: chromosome, cumulative start position, cumulative stop position
cumulative chromosome starts used in plotting.</p>
</dd>
<dt class="field-odd">Example</dt>
<dd class="field-odd"><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.association</span> <span class="kn">import</span> <span class="n">single_snp</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pysnptools.snpreader</span> <span class="kn">import</span> <span class="n">Bed</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">fastlmm.util</span> <span class="kn">import</span> <span class="n">example_file</span> <span class="c1"># Download and return local file name</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">fastlmm.util.util</span> <span class="k">as</span> <span class="nn">flutil</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">test_snps</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.5chrom.*&quot;</span><span class="p">,</span><span class="s2">&quot;*.bed&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pheno_fn</span> <span class="o">=</span> <span class="n">example_file</span><span class="p">(</span><span class="s2">&quot;fastlmm/feature_selection/examples/toydata.phe&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">results_dataframe</span> <span class="o">=</span> <span class="n">single_snp</span><span class="p">(</span><span class="n">test_snps</span><span class="o">=</span><span class="n">test_snps</span><span class="p">,</span> <span class="n">pheno</span><span class="o">=</span><span class="n">pheno_fn</span><span class="p">,</span> <span class="n">h2</span><span class="o">=</span><span class="mf">.2</span><span class="p">,</span> <span class="n">count_A1</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">chromosome_starts</span> <span class="o">=</span> <span class="n">flutil</span><span class="o">.</span><span class="n">manhattan_plot</span><span class="p">(</span><span class="n">results_dataframe</span><span class="p">[[</span><span class="s2">&quot;Chr&quot;</span><span class="p">,</span> <span class="s2">&quot;ChrPos&quot;</span><span class="p">,</span> <span class="s2">&quot;PValue&quot;</span><span class="p">]],</span><span class="n">pvalue_line</span><span class="o">=</span><span class="mf">1e-7</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1">#plt.show()</span>
</pre></div>
</div>
</dd>
</dl>
</dd></dl>

</div>
</div>
<div class="section" id="indices-and-tables">
<h2>Indices and Tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h2>
<blockquote>
<div><ul class="simple">
<li><p><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></p></li>
<li><p><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></p></li>
<li><p><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></p></li>
</ul>
</div></blockquote>
</div>
</div>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="#">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fastlmm</span></code> Documentation</a><ul>
<li><a class="reference internal" href="#single-snp"><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp</span></code></a></li>
<li><a class="reference internal" href="#single-snp-scale"><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_scale</span></code></a></li>
<li><a class="reference internal" href="#single-snp-all-plus-select"><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_all_plus_select</span></code></a></li>
<li><a class="reference internal" href="#single-snp-linreg"><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_linreg</span></code></a></li>
<li><a class="reference internal" href="#single-snp-select"><code class="xref py py-mod docutils literal notranslate"><span class="pre">single_snp_select</span></code></a></li>
<li><a class="reference internal" href="#epistasis"><code class="xref py py-mod docutils literal notranslate"><span class="pre">epistasis</span></code></a></li>
<li><a class="reference internal" href="#snp-set"><code class="xref py py-mod docutils literal notranslate"><span class="pre">snp_set</span></code></a></li>
<li><a class="reference internal" href="#fastlmm"><code class="xref py py-class docutils literal notranslate"><span class="pre">FastLMM</span></code></a></li>
<li><a class="reference internal" href="#linearregression"><code class="xref py py-class docutils literal notranslate"><span class="pre">LinearRegression</span></code></a></li>
<li><a class="reference internal" href="#heritability-spatial-correction"><code class="xref py py-mod docutils literal notranslate"><span class="pre">heritability_spatial_correction</span></code></a></li>
<li><a class="reference internal" href="#util-module"><code class="xref py py-mod docutils literal notranslate"><span class="pre">util</span></code> Module</a><ul>
<li><a class="reference internal" href="#util-compute-auto-pcs"><code class="xref py py-mod docutils literal notranslate"><span class="pre">util.compute_auto_pcs</span></code></a></li>
<li><a class="reference internal" href="#util-manhattan-plot"><code class="xref py py-mod docutils literal notranslate"><span class="pre">util.manhattan_plot</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#indices-and-tables">Indices and Tables</a></li>
</ul>
</li>
</ul>

  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/index.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="nav-item nav-item-0"><a href="#">fastlmm 0.0.1 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">fastlmm</span></code> Documentation</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright .
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.0.2.
    </div>
  </body>
</html>